import xml.etree.ElementTree as ET
from xml.dom import minidom

# 查看XML文件内容
def display_xml_content(file_path):
    try:
        # 使用minidom来美化XML输出
        with open(file_path, 'r', encoding='utf-8') as f:
            xml_content = f.read()
            
        # 解析并美化XML
        parsed_xml = minidom.parseString(xml_content)
        pretty_xml = parsed_xml.toprettyxml(indent="  ")
        
        print(f"XML文件 '{file_path}' 的内容：")
        print(pretty_xml)
        
    except Exception as e:
        print(f"读取XML文件时发生错误：{str(e)}")

# 执行函数查看XML内容
display_xml_content('example.xml')